package com.chenjiaru.util.entity.page;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * es的分页对象
 * @param <T>
 */
@Data
public class Page<T> {
    /**偏移数（下标从0开始）**/
    private Integer from;
    /**分页数**/
    private Integer size;
    /**总页数**/
    private Long totalPage;
    /**总记录**/
    private Long totalCount;
    /**分页记录**/
    private List<T> list;

    public Page(int from, int size, long totalCount, List<T> list) {
        this.from = from;
        this.size = size;
        this.totalCount = totalCount;
        this.list = list;
        //计算总页数
        if (totalCount % size == 0) {
            this.totalPage = totalCount / size;
        } else {
            this.totalPage = (totalCount / size) + 1;
        }
    }

}
